package com.hsd.voice_asr.socket;


import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class TCPControlServer extends Thread {

    public volatile boolean flag = true;

    public void run() {
        try {
            ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
            serverSocketChannel.socket().bind(new InetSocketAddress("0.0.0.0", 9999));
            SocketChannel socketChannel;
            while (flag) {
                try {
                    socketChannel = serverSocketChannel.accept();
                    SocketControlThread socketControlThread = new SocketControlThread(socketChannel);
                    socketControlThread.start();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            serverSocketChannel.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
